!(function($){
	var Timer = function(fun, ms){
		var timer,
			delay = ms;

		return {
			start: function(){
				timer = setInterval(fun, delay);
			},
			stop: function(){
				timer && clearInterval(timer);
			},
			setDelay: function(ms){
				delay = ms;
			}
		};
	}
	
    var Scroll = function($el, options){
		var opts = $.extend({}, options);
		
		// 延迟
		var delay = opts.delay ? opts.delay : 5000;
		// 速度
		var speed = opts.speed ? opts.speed : 1000;
		// 可见个数
		var vis = opts.vis ? opts.vis : 1;
		// 滚动元素子元素
		var $items = $el.children();
		// 个数
		var sLen = $items.size();
		// 子元素高度
		var oHeight = $items.outerHeight(true);

		var run = function(){
			$el.animate({
				'margin-top': -oHeight
			}, speed, function() {
				$el.css('margin-top', 0);
				$el.append($el.children(":first"));
			});
		}

		var timer = new Timer(run, delay);

		return {
			start: function(){
				timer.stop();
				if (sLen > vis) {
					timer.start();
				}
			},
			stop: function(){
				timer.stop();
			}
		};
	}

	var App = function(){
		var cfg = {
			type: 1,
			area: ["789px", "505px"],
			shade: .5,
			shadeClose: true
		}
		return {
			init: function(){
				new Scroll($("#notice-list")).start();
				$(".open-le").on("click", function(){
					App.latestEvents();
				});

				$(".open-aj").on("click", function(){
					App.agencyJoin();
				});

				$(".open-faq").on("click", function(){
					App.faq();
				});

				$(".open-au").on("click", function(){
					App.aboutus();
				});
				$(".open-au1").on("click", function(){
					App.aboutus1();
				});

				// add by ag....
				$("#ag-home").on("click", function() {
					Util.jumpUrl({
						file: "index.html"
					});
				});
				$("#ag-kf").on("click", function() {
					_MEIQIA('showPanel');
				});
				$(".code .c2").on("click", function() {
					Util.jumpUrl({
						file: "register.html",
					});
				});
				$("#ag-try").on("click", function() {
					urlInfo.params.try = 1;
					CMD.trial(function(r) {
						Util.jumpUrl({
							file: 'agreement.html',
							try: 1,
						});
					});
				});
				$("a.ljkh").on("click", function() {
					Util.jumpUrl({
						file: "register.html",
					})
				});
				$(".code a.c1").on("click", function() {
					var account = $("#username").val().trim();
					var p = $("#login-password").val().trim();
					if (!account) {
						alert("请输入账号！");
						return false;
					}
					if (!p) {
						alert("请输入登录密码！");
						return false;
					}

					// 登录请求
					urlInfo.params.try = 0;
					CMD.signin(account, p, "pc", function(r) {
						Util.jumpUrl({
							file: 'agreement.html',
							try: 0,
						});
					}, function(message) {
						if (message)
							message = message.replace("登入认证失败！", "账号或登录密码不对！")
						alert(message || '账号或登录密码不对！');
					});
					return false;
				})
			},
			latestEvents: function(){
				layer.open($.extend({}, cfg, {
					title: "&nbsp;",
					content: $("#latestEvents")
				}));
			},
			agencyJoin: function(){
				layer.open($.extend({}, cfg, {
					title: "&nbsp;",
					content: $("#agencyJoin")
				}));
			},
			faq: function(){
				layer.open($.extend({}, cfg, {
					title: "&nbsp;",
					content: $("#faq")
				}));
			},
		aboutus1: function(){
				layer.open($.extend({}, cfg, {
					title: "&nbsp;",
					content: $("#download")
				}));
			},
			aboutus: function(){
				layer.open($.extend({}, cfg, {
					title: "&nbsp;",
					content: $("#aboutus")
				}));
			}
		};
	}();
	
	$(function(){
		App.init();
	});
}(jQuery));